﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Model
{
    [ObjectEvent]
    public class Reimu_C001Event : ObjectEvent<Reimu_C001>, IAwake
    {
        public void Awake()
        {
            Get().Awake();
        }
    }
    /*
     * Center:攻击阶段，当你具有稳定特性的符卡击破对阵符卡时， 你可回复500点体力，并将该卡返回卡组.
     * Hyper:「行云流水」对非稳定特性的符卡同样生效； 本局游戏你发动至少一次 HYPER 后，若进入华丽度胜负结算， 你所有宣言区符卡的华丽度均+1 
     * */
    public class Reimu_C001 : BattleEventComponent
    {
        int DefenceNum, AttackNum;
        bool IfRemove;
        int PowerAdd;
        bool Hypered = false;
        public override BattleEventType[] EventType { get; set; } = new BattleEventType[] { BattleEventType.AttackSuccess, BattleEventType.GorgeousCal, BattleEventType.BattleStatusSwitch };

        public override async Task RunEvent(BattleEventType eventType, FightModel fightModel, params object[] param)
        {
            BattleCard CharactorCard = GetEntity<BattleCard>();           
            if (eventType == BattleEventType.AttackSuccess && CharactorCard.IfCenter)
            {
                await CloudAndWater(fightModel, CharactorCard.IfHyper, param);
            }
            if (eventType == BattleEventType.GorgeousCal && Hypered)
            {
                GorgeousInfo gorgeousInfo = param[0] as GorgeousInfo;
                foreach (var a in gorgeousInfo.Cards)
                {
                    a.GetComponent<SpellCardComponent>().Gorgeous += 1;
                }
            }
            if (eventType == BattleEventType.BattleStatusSwitch)
            {
                if (CharactorCard.IfHyper) Hypered = true;
            }
        }

        private async Task CloudAndWater(FightModel fightModel, bool IfHyper, params object[] param)
        {
            DamageInfo damageInfo = param[0] as DamageInfo;
            BattleCard CharactorCard = GetEntity<BattleCard>();
            if (CharactorCard.Owner != damageInfo.AttackCard.Owner)
            {
                return;
            }
            if ((damageInfo.AttackCard.GetComponent<Features_StableComponent>()!=null) || (IfHyper))
            {
                DecideInfo decideInfo = new DecideInfo()
                {
                    Describe = "是否发动[行云流水]？",
                    CallBack = () =>
                    {
                        BattlePlayer battlePlayer = fightModel.GetAttackPlayer();
                        DamageInfo damageInfo1 = new DamageInfo
                        {
                            DamageValue = -500,
                            DamageType = DamageTypeEnum.Other,
                            AttackCard = damageInfo.AttackCard,
                        };
                        battlePlayer.ChangeHp(damageInfo1);
                        Log.Debug($"{battlePlayer.Name}因为[行云流水]的效果恢复了500点体力");
                        damageInfo.AttackCard.Move(battlePlayer[CardPlace.Deck]);
                        battlePlayer[CardPlace.Deck].Shuffle();
                        Log.Debug($"{damageInfo.AttackCard.CardName}返回了卡组");
                    },
                };
                await BattleEventWatcherComponent.Single.RunEvent(BattleEventType.ShowWindow, fightModel,WindowType.Ask, decideInfo);
            }
            
        }
    }
}
